package com.mygdx.game.Stage.Fight;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;

public class Fighter extends Actor {
    //基础属性
    public float maxHp=0;
    public float hp=0;
    public int shield=0;
    public BloodBar bloodBar;

    //左侧人物的大小、图片地址、位置
    public int x = 0;
    public int y = 0;
    public float width = 0;
    public float height = 0;
    public String image = "";

    public int currentImage=0;
    public TextureRegion[] walkFrame;

    public Fighter(String path){
        super();
        image = path;
        bloodBar = new BloodBar();
        show();
    }

    public void show(){
        Texture[] temp = new Texture[4];
        walkFrame =new TextureRegion[4];
        for(int i=0;i<4;i++){
            temp[i] = new Texture(Gdx.files.internal(image+" ("+(4-i)+").png"));
            width =  temp[i].getWidth();
            height = temp[i].getHeight();
            walkFrame[i] = new TextureRegion(temp[i],0,0,400,400);

        }
    }

    public void setPosition(int x, int y) {
        this.x=x;
        this.y=y;
        bloodBar.set(this.x,this.y,this.maxHp,this.hp);
    }

    @Override
    public void draw(Batch batch, float parentAlpha){
        uploadState();
        batch.draw(walkFrame[currentImage],x,y);
        currentImage++;
        if (currentImage==4) currentImage=0;
    }

    @Override
    public void act(float delta) {
        super.act(delta);
    }

    public void uploadState(){
        bloodBar.set(this.x,this.y,this.maxHp,this.hp);

    }


    //这些方法拿来构建游戏战斗的逻辑，血怎么扣什么的
    public void attacked(int value){
        if (shield>0){
            if (shield-value<0){
                hp+=shield-value;
                shield=0;
            }
            shield-=value;
        }
    }

    //所有角色的回合结束动作，不动！
    public void roundAction(){}

    //角色死亡动作
    public void deadAction(){}

    //动作1，具体需要重写，在这里也不动
    public void action1(){ }

    //动作2，具体需要重写，在这里也不动
    public void action2(){ }

    //动作3，具体需要重写，在这里也不动
    public void action3(){ }

    //动作4，具体需要重写，在这里也不动
    public void action4(){ }
}
